<?php

namespace App\Http\Controllers\Reception\Link;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\URL;
use Illuminate\Http\Request;

//友链模块
class LinkController extends Controller
{

    public function getLinkList(Request $request)
    {
        $token = $request->query('token');
        //验证权限
        $verifytoken = verifytokens($token);
        if (is_array($verifytoken)) {
            return $verifytoken;
        }
        $page = (int) $request->query('page');
        $pageSize = (int) $request->query('pageSize');
        //翻页
        $page = $page - 1;
        if ($page != 0) {
            $page = $pageSize * $page;
            $pageSize = $pageSize * $page;
        }
        $info = DB::table('link')
            ->leftjoin('upload_file', 'link.fileid', '=', 'upload_file.fileid')
            ->orderByDesc("link_create_time")
            ->offset($page)
            ->limit($pageSize)
            ->get();
        if ($info) {
            $info = json_decode($info, true);
            foreach ($info as $key => $value) {
                $info[$key]['url'] =  http_type() . $_SERVER['HTTP_HOST'] . "/" . $value['url'] . "/" . $value['file_name'];
            }
            $data = success();
            $data['data'] = $info;
        } else {
            $data = fail();
        }
        return $data;
    }
}